home *** CD-ROM | disk | FTP | other *** search
- Path: news.rain.org!usenet
- From: "Guus Leeuw jr." <guusl@eiffel.com>
- Newsgroups: comp.lang.c++
- Subject: Re: When to use "->" vs "." when calling Member functions
- Date: Tue, 16 Jan 1996 19:14:21 -0800
- Organization: ISE Inc. http://www.eiffel.com
- Message-ID: <30FC698D.6D216C84@eiffel.com>
- References: <4dhea1$6v8@ornews.intel.com>
- NNTP-Posting-Host: @outback.eiffel.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0b3 (X11; I; Linux 1.2.8 i586)
-
- Thurman Miller wrote:
- >
- > I'm confused, so please no harsh remarks :)
- >
- > If I've got:
- >
- > class Cfoo
- > {
- > something * getptr();
- > somethingelse* m_other;
- > }
- >
- > something * foo::getptr()
- > {
- > return m_other;
- > }
- >
- > Now...if I'm in another class....
- >
- > Cfoo foo;
- > somethingelse* = foo.getptr();
- >
- > why doesn't the following work?
- >
- > somethingelse* = foo->getptr();
- >
- > I get compile error about no "->" overloaded operator....
- >
- > Can someone point out the obvious when I use one notation over
- > another?
- >
- > TIA
- >
- > Thurman
-
- Okay, here we go.
-
- When you write "foo->getptr()", you're actually writing
- "(*foo).getptr()". And that is where your problem is.
-
- The selector (`xyz->abc') is used as a shorthand notation for
- `(*xyz).abc', and therefor can only be aplied to pointers to objects. As
- in:
- Cfoo *foo;
- somethingelse* = foo->getptr();
-
- Hope this explains,
- Guus Leeuw jr.
-